---@class MainApp_ItemRenderer
local MainApp_ItemRenderer = require('MainApp/SelectPage/MainApp_ItemRenderer')

MainApp = {}
local this = MainApp

local transform
local gameObject

function MainApp.Awake(go,refAssets)
	this.gameObject = go
	this.transform = go.transform
	logWarn("Awake lua--->>"..go.name);
end

function MainApp.OnEnable()
	-- body
	logWarn("OnEnable lua--->>"..this.gameObject.name);







--  local _rt = UnityEngine.RenderTexture.New(UnityEngine.Screen.width,UnityEngine.Screen.height,24,UnityEngine.RenderTextureFormat.RGB565);
-- _rt.autoGenerateMips = false;
-- local cam = UnityEngine.Camera.main;
-- cam.targetTexture = _rt;
-- cam:Render();
-- cam.targetTexture = null;

-- local t = Util.RenderTextureToTexture2D(_rt , UnityEngine.Rect.New(0,0,_rt.width,_rt.height) )
-- local bytes = t:EncodeToJPG(100)

-- Util.WriteBytes(UnityEngine.Application.streamingAssetsPath..'/cc.png',bytes)


	

	--test sqlite
	-- SQLite.Instance:SetValue("MainApp","mainapp_makeup_facepaint_2",Util.GetTime());
	
	-- if SQLite.Instance:ContainKey("MainApp","mainapp_makeup_facepaint_2") then
	-- 	local val = SQLite.Instance:GetValue("MainApp","mainapp_makeup_facepaint_2",0);
	-- 	logError('sqlite test >> '..val);

	-- 	-- SQLite.Instance.Delete("MainApp","mainapp_makeup_facepaint_2");
	-- end

	-- SQLite.Instance:SetValue("SonApp","test_bool",true)

	-- logError('sqlite test >> '.. tostring(SQLite.Instance:GetValue("SonApp","test_bool",false)) );
end


function MainApp.Start()
	logWarn("Start lua--->>"..this.gameObject.name);

	--测试加载图片
	local asset = ResManager.Asset.New("MainAppRaw/MotionBar.png",ResManager.AssetType.Sprite)
	resMgr:LoadAsset(asset,this.OnLoaded)

	
	--测试创建类
	for i=1,10 do
		MainApp_ItemRenderer.New()
	end


	--Test Unity Event
	 Messenger.AddListener("Event",function()
	 	-- body
	 	logWarn("----------------")
	 end)
	 Messenger.DispatchEvent("Event")
end

function MainApp.OnLoaded(asset)
	local sp = find("Sp")
	if sp ~= nil then
		local spRender = sp:GetComponent('SpriteRenderer')
		spRender.sprite = asset.sprite
		spRender:DOFade(0.5,1):SetDelay(1):SetEase(DG.Tweening.Ease.InOutBounce)

		sp.transform:DOLocalMoveX(2,2):OnComplete(function()
				logWarn('ease end') 
			end)
	end
end

function MainApp.OnDisable()
	-- body
	logWarn("OnDisable lua--->>"..this.gameObject.name);
end

function MainApp.OnDestroy()
	logWarn("Destroy lua--->>"..this.gameObject.name);
end

return MainApp